<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<script src="/js/axios.min.js"></script>
<script src="/js/util.js"></script>
<script>
    var postId=getQuery("postId");

    window.onload=function (){
        init();
    }

    function init(){
        axios.get("/post/findById",{
            params:{
                id:postId
            }
        }).then(resp=>{
            var info = resp.data;
            $("username").innerHTML=info.user.username;
            $("faceImg").src="/face/"+info.user.face;
            $("regDate").innerHTML=info.user.regDate;
            $("postTitle").innerHTML=info.title;
            $("time").innerHTML=info.time;
           $("postContent").innerHTML=info.content;

           var str = "";
           info.replayList.forEach(r=>{
               str+=`<tr><td>${r.title}</td><td>${r.user.username}</td><td>${r.content}</td><td>${r.time}</td></tr>`;
           })
            $("replayData").innerHTML=str;
        })
    }

    function addReplay(){
        axios.get("/replay/add",{
            params:{
                postId,
                title:$("titleText").value,
                content:$("contentText").value
            }
        }).then(resp=>{
            if (resp.data=="ok"){
                location.href="replay.html?postId="+postId;
            }
        })
    }


</script>
<style>div{border: 1px solid}</style>
<body>
<div style="display: flex">
    <div style="width: 20%">
        楼主：<span id="username"></span><br>
        <img src="" width="50" height="50" id="faceImg">
        注册日期：<span id="regDate"></span>
    </div>
    <div>
      主题：  <span id="postTitle"></span> @ <span id="time"></span><br>
        <span id="postContent"></span>
    </div>
</div>
回帖：
<table border="1px" width="100%" cellspacing="1">
    <thead>
    <tr>
        <th>主题</th>
        <th>作者</th>
        <th>内容</th>
        <th>回帖时间</th>
    </tr>
    </thead>
    <tbody id="replayData"></tbody>
</table>
回复帖子<br>
标题：<input id="titleText"><br>
内容：<textarea id="contentText"></textarea><br>
<input type="button" value="发表" onclick="addReplay()">

</body>
</html>